<div class="container-fluid">
    <div class="wrapper">
        <div class="panel" id="nav">
            <div class="panel-heading">
                <h3 class="panel-title">单个sku库存查询</h3>
            </div>
            <div class="panel-body">

                <form action="__URL__/index" method="get">
                    <div class="container-fluid">
                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">请输入SKU号</span>
                                <input class="form-control" type="text" name="sku" onkeyup="this.value=trim(this.value)"
                                       value="{$_GET['sku']|default=''}">
                            </div>
                        </div>

                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">所属公司主体</span>
                                <select name="enterprise_dominant" id="enterprise_dominant" class="form-control">
                                    <option value="">--请选择--</option>
                                    <volist name="enterprise_dominant" id="val" key="num">
                                        <option value="{$num}">{$val}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>

                        <div class="col-sm-12 col-md-3  add-space">
                            <div class="input-group input-group-md">
                                <span class="input-group-addon">站点</span>
                                <select name="site_id" id="site_id" class="form-control">
                                    <option value="">--请选择--</option>
                                    <volist name="sites" id="value">
                                        <option value="{$key}">{$value}</option>
                                    </volist>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3  add-space">
                            <input class="btn btn-primary" type="button" id="serach" value="查询">
                            <input class="btn btn-primary" type="button" onclick="reset()" value="重置">
                        </div>

                    </div>
                </form>
                <div class="clearfix"></div>
                <div id="pageContent" class="well">

                    <div id="content">
                        <h4>SKU状态</h4>
                        <hr/>
                        <div class="col-md-3">
                            <span>在售状态：</span>
                            <span class="xia">{$skuStatusAndPlace['status']|default=''}</span>
                        </div>
                        <div>
                            <span>sku主仓库：</span>
                            <span class="xia">{$skuStatusAndPlace['location']|default=''}</span>
                        </div>

                        <hr>
                        <h4>储位库存信息</h4>
                        <table class="table table-striped  table-hover" cellspacing="0" width="100%">
                            <tbody>
                            <tr>
                                <th>sku</th>
                                <th>中文名称</th>
                                <th>是否出口退税</th>
                                <th>储位</th>
                                <th>可用库存</th>
                            </tr>
                            <tbody>
                            <?php foreach($skuStorageInventories as $_skuStorageInventories) { ?>
                            <tr>
                                <td>{$_skuStorageInventories.sku|default=''}</td>
                                <td>{$_skuStorageInventories.sku_name|default=''}</td>
                                <td><?php  switch($_skuStorageInventories['export_tax_rebate']) {
                                                case '0':
                                                    echo '非出口退税';
                                                    break;
                                                case '1':
                                                    echo '1出口退税';
                                                    break;
                                            }
                                    ?>
                                </td>
                                <td>{$_skuStorageInventories.storage_position|default=''}</td>
                                <td>{$_skuStorageInventories.all_available_quantity|default=0}</td>
                            </tr>
                            <?php } ?>
                            </tbody>
                        </table>

                        <hr>
                        <h4>非出口退税库存明细</h4>
                        <hr/>
                        <div class="col-md-3">
                            <span>期初库存数量：</span>
                            <span class="xia">{$stocks.open_stock|default=0}</span>
                        </div>
                        <div class="col-md-3">
                            <span>本月入库数量：</span>
                            <span class="xia">{$stocks.wo_num|default=0}</span>
                        </div>
                        <div class="col-md-3">
                            <span>本月出库数量：</span>
                            <span class="xia">{$stocks.do_num|default=0}</span>
                        </div>
                        <div class="clearfix"></div>
                        <hr/>
                        <div>
                            <span>实际库存数量(期初库存数量+本月入库数量-本月出库数量)：</span>
                            <span class="xia">{$stocks.stock|default=0}</span>
                        </div>
                        <hr/>
                        <div>
                            <span>总在途数量（已采购未入库的数量,未完结的采购量-入库量）：</span>
                            <span class="xia">{$stocks.onway_num|default=0}</span>
                        </div>
                        <hr/>
                        <div>
                            <span>总未发数量（订单物品新录入、已通过、已打印、缺货减去未发货已扫描出库的数量）：</span>
                            <span class="xia">{$stocks.order_occupy_num|default=0}</span>
                        </div>
                        <hr/>
                        <div>
                            <span>库存可用数量（实际库存数量-总未发量）：</span>
                            <span class="xia">{$stocks.actual_available_num|default=0}</span>
                        </div>
                        <hr/>
                        <div>
                            <span>总可用数量（库存可用数量+总在途数量）：</span>
                            <span class="xia">{$stocks.all_available_num|default=0}</span>
                        </div>
                        <hr/>
                        <h4>当月的库存数量及成本明细</h4>
                        <table class="table table-striped  table-hover" cellspacing="0" width="100%">
                            <tbody>
                            <tr>
                                <th rowspan="2">sku</th>
                                <th rowspan="2">中文名称</th>
                                <th rowspan="2">规格</th>
                                <th colspan="2">期初</th>
                                <th colspan="2">本期入</th>
                                <th colspan="2">本期出</th>
                                <th colspan="2">期末结存</th>
                            </tr>
                            <tr>
                                <th>数量</th>
                                <th>成本</th>
                                <th>数量</th>
                                <th>成本</th>
                                <th>数量</th>
                                <th>成本</th>
                                <th>数量</th>
                                <th>成本</th>
                            </tr>
                            <tr>
                                <td>{$stocks.sku|default='SKU'}</td>
                                <td>{$stocks.sku_name|default='SKU中文名'}</td>
                                <td>{$stocks.sku_standard|default=''}</td>
                                <td>{$stocks.open_stock|default=0}</td>
                                <td>{$stocks.open_cost|default=0}</td>
                                <td>{$stocks.wo_num|default=0}</td>
                                <td>{$stocks.wo_cost|default=0}</td>
                                <td>{$stocks.do_num|default=0}</td>
                                <td>{$stocks.do_cost}</td>
                                <td>{$stocks['open_stock']+$stocks['wo_num']-$stocks['do_num']}</td>
                                <td>{$stocks['open_cost']+$stocks['wo_cost']-$stocks['do_cost']}</td>
                            </tr>
                            </tbody>
                        </table>

                        <br>
                        <br>
                        <hr>
                        <h4>出口退税库存明细</h4>
                        <hr/>
                        <div class="col-md-3">
                            <span>期初库存数量：</span>
                            <span class="xia">{$taxstocks.open_stock|default=0}</span>
                        </div>
                        <div class="col-md-3">
                            <span>本月入库数量：</span>
                            <span class="xia">{$taxstocks.wo_num|default=0}</span>
                        </div>
                        <div class="col-md-3">
                            <span>本月出库数量：</span>
                            <span class="xia">{$taxstocks.do_num|default=0}</span>
                        </div>
                        <div class="clearfix"></div>
                        <hr/>
                        <div>
                            <span>实际库存数量(期初库存数量+本月入库数量-本月出库数量)：</span>
                            <span class="xia">{$taxstocks.stock|default=0}</span>
                        </div>
                        <hr/>
                        <div>
                            <span>总在途数量（已采购未入库的数量,未完结的采购量-入库量）：</span>
                            <span class="xia">{$taxstocks.onway_num|default=0}</span>
                        </div>
                        <hr/>
                        <div>
                            <span>总未发数量（订单物品新录入、已通过、已打印、缺货减去未发货已扫描出库的数量）：</span>
                            <span class="xia">{$taxstocks.order_occupy_num|default=0}</span>
                        </div>
                        <hr/>
                        <div>
                            <span>库存可用数量（实际库存数量-总未发量）：</span>
                            <span class="xia">{$taxstocks.actual_available_num|default=0}</span>
                        </div>
                        <hr/>
                        <div>
                            <span>总可用数量（库存可用数量+总在途数量）：</span>
                            <span class="xia">{$taxstocks.all_available_num|default=0}</span>
                        </div>
                        <hr/>
                        <h4>当月的库存数量及成本明细</h4>
                        <table class="table table-striped  table-hover" cellspacing="0" width="100%">
                            <tbody>
                            <tr>
                                <th rowspan="2">sku</th>
                                <th rowspan="2">中文名称</th>
                                <th rowspan="2">规格</th>
                                <th colspan="2">期初</th>
                                <th colspan="2">本期入</th>
                                <th colspan="2">本期出</th>
                                <th colspan="2">期末结存</th>
                            </tr>
                            <tr>
                                <th>数量</th>
                                <th>成本</th>
                                <th>数量</th>
                                <th>成本</th>
                                <th>数量</th>
                                <th>成本</th>
                                <th>数量</th>
                                <th>成本</th>
                            </tr>
                            <tr>
                                <td>{$taxstocks.sku|default='SKU'}</td>
                                <td>{$taxstocks.sku_name|default='SKU中文名'}</td>
                                <td>{$taxstocks.sku_standard|default=''}</td>
                                <td>{$taxstocks.open_stock|default=0}</td>
                                <td>{$taxstocks.open_cost|default=0}</td>
                                <td>{$taxstocks.wo_num|default=0}</td>
                                <td>{$taxstocks.wo_cost|default=0}</td>
                                <td>{$taxstocks.do_num|default=0}</td>
                                <td>{$taxstocks.do_cost|default=0}</td>
                                <td>{$taxstocks['open_stock']+$taxstocks['wo_num']-$taxstocks['do_num']}</td>
                                <td>{$taxstocks['open_cost']+$taxstocks['wo_cost']-$taxstocks['do_cost']}</td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>

    /**
     * 去掉字符串左右两侧的空格
     * @param str
     * @returns {void|string|XML}
     */
    function trim(str) {
        return str.replace(/(^\s*)|(\s*$)/g, "");
    }

    $(function () {
        $("select[name='enterprise_dominant']").val("<?php  echo $_GET['enterprise_dominant'];?>");
        $("select[name='site_id']").val("<?php  echo $_GET['site_id'];?>");

    });

    /**
     * 下载
     */
    $("#serach").click(function () {
        var param = '';
        var sku = $("input[name='sku']").val();
        var enterprise_dominant = $("select[name='enterprise_dominant']").val();
        var site_id = $("select[name='site_id']").val();
        if ($.trim(sku) != '') {
            param += "&sku=" + sku;
        }
        if ($.trim(enterprise_dominant) != '') {
            param += "&enterprise_dominant=" + $.trim(enterprise_dominant);
        }
        if ($.trim(site_id) != '') {
            param += "&site_id=" + $.trim(site_id);
        }
        if(sku==''){
            layer.msg('请输入sku',{'icon':'5'});return;
        }
        if(enterprise_dominant==''){
            layer.msg('请选择主体',{'icon':'5'});return;
        }
        if(site_id==''){
            layer.msg('请选择站点',{'icon':'5'});return;
        }
        if (param != '') {
            param = '?' + param.substr(1);
        }
        window.location.href = '__URL__/index' + param;
    });

    /**
     * 重置
     * */
    function reset() {
        $('#form_search').find('input').val('');
        $('#form_search').find('select').val('');
    }
</script>